<?php
// $vAllTrees = AFT_MakeTreeDB('');
$vSections = AFT_load('sections');
$settings = AFT_load('settings');
foreach ($vSections as $vsec2) {
	$secHTML .=  "<option value=\"{$vsec2['id']}\">{$vsec2['name']} ({$vsec2['id']})</option>";
}
?>

<style>
table.settings {
	margin-left:auto;
	margin-right:auto;
}
table.settings td, table.settings th {
	padding:4px;
	text-align:left;
	vertical-align:top;
}
table.settings th {
	background-color:#404040;
	color:white;
	border-top:1px solid white;
}
table.settings input[type=button] {
	font-size:10px;
	background-color:#e0e0e0;
	width:100%;
}

</style>

<table class="settings">
	<caption>Settings</caption>
	<tr>
		<th width="80">Giftbox</th>
		<td>
			<input type="button" value="Clear All Actions" onclick="actionconf('faction=general&actn=clearallgb')"><br>
			<input type="button" value="Place All Trees" onclick="actionconf('faction=general&actn=placeallgb')"><br>
			<input type="button" value="Place All un-mastered Trees" onclick="actionconf('faction=general&actn=placeallugb')"><br>
			<input type="checkbox" class="saveConf" name="settings-GBPlaceUnmastered" <?=$settings['GBPlaceUnmastered']?" checked":""?> > always place all un-mastered trees
			<input type="checkbox" class="saveConf" name="settings-GBSellMastered" <?=$settings['GBSellMastered']?" checked":""?> > always sell all mastered trees (but keep precious)
		</td>
	</tr>

	<tr>
		<th>Mystery Seedlings</th>
		<td>
			<input type="button" value="Clear all actions" onclick="actionconf('faction=general&actn=clearallseed')"><br>
			Water all known Seedlings (count <input id="waterallseedcnt" size="2" value="-1">)
				<input style="width:auto;" type="button" value="set" onclick="actionconf('faction=general&actn=waterallseed&waterallseedcnt='+$('#waterallseedcnt').val())"><br>
			Water all un-mastered seedlings (count <input id="wateralluseedcnt"  size="2" value="19">)
				<input style="width:auto;" type="button" value="set" onclick="actionconf('faction=general&actn=wateralluseed&wateralluseedcnt='+$('#wateralluseedcnt').val())"><br>
			Sell all known Seedlings (count <input id="sellallseedcnt"  size="2" value="-1">)
				<input style="width:auto;" type="button" value="set" onclick="actionconf('faction=general&actn=sellallseed&sellallseedcnt='+$('#sellallseedcnt').val())">
			<br>
			<input name="settings-autoPlaceSeedlings" class="saveConf" type="checkbox"<?=$settings['autoPlaceSeedlings']?" checked":""?>> Automatically place seedlings,
			but keep <input name="settings-autoPlaceSeedlingsKeep" class="saveConf" size="4" value="<?=$settings['autoPlaceSeedlingsKeep']?>"><br>
			Default action for...<br>
			...un-mastered seedlings:
			<select name="settings-seedUnmasteredAction" class="saveConf">
				<option value="" <?=$settings['seedUnmasteredAction'] == ''?" selected":""?> >do nothing</option>
				<option value="sell" <?=$settings['seedUnmasteredAction'] == 'sell'?" selected":""?> >sell</option>
				<option value="water" <?=$settings['seedUnmasteredAction'] == 'water'?" selected":""?> >water</option>
			</select>
			...mastered seedlings:
			<select name="settings-seedMasteredAction" class="saveConf">
				<option value="" <?=$settings['seedMasteredAction'] == ''?" selected":""?> >do nothing</option>
				<option value="sell" <?=$settings['seedMasteredAction'] == 'sell'?" selected":""?> >sell</option>
				<option value="water" <?=$settings['seedMasteredAction'] == 'water'?" selected":""?> >water</option>
			</select>
		</td>
	</tr>

	<tr>
		<th>Breeding</th>
		<td>
			<input type="button" value="For Mastery" onclick="actionconf('faction=general&actn=bredmastery')"><br>
			<input type="button" value="For Coins" onclick="actionconf('faction=general&actn=bredcoins')"><br>
			<input type="button" value="For Coconuts" onclick="actionconf('faction=general&actn=bredcoconuts')">
			<input type="button" value="Clear all BREEDING actions" onclick="actionconf('faction=general&actn=clearallbred')"><br>
			<!-- Default breeding action for unknown trees: -->
			Breeding order: 
			<select name="settings-breedingOrder" size="1" class="saveConf">
			<?php foreach (array('realname', 'mastery', 'coins', 'cocos', 'date', 'cnt') as $k) { 
				echo "<option value=\"$k\"". ($settings['breedingOrder']==$k?' selected':'').">$k</option>\n";
			} ?>
			</select>
			<select name="settings-breedingOrderDir" size="1" class="saveConf">
				<option value="asc" <?= $settings['breedingOrderDir']=='asc'?' selected':''?>>ascending</option>
				<option value="desc" <?= $settings['breedingOrderDir']=='desc'?' selected':''?>>descending</option>
			</select>

		</td>
	</tr>

	<tr>
		<th>Trees</th>
		<td>
			<input type="button" value="Clear all SELL actions" onclick="actionconf('faction=general&actn=clearallsell')"><br>
			Sell all trees, but keep
				<input id="treecount" size="2" value="0">,
				<input id="keepprecious" type="checkbox" checked> keep precious
				<input id="keepunmastered" type="checkbox" checked> keep un-mastered
				<input type="button" style="width:auto;" value="set"
					onclick="actionconf('faction=sellalltrees&keep='+($('#treecount').val())
						+'&keepprecious='+($('#keepprecious').attr('checked')?'1':'')
						+'&keepunmastered='+($('#keepunmastered').attr('checked')?'1':'')
						)"><br>
			<input name="settings-autoSellMastered" class="saveConf" type="checkbox"<?=$settings['autoSellMastered']?" checked":""?>> Auto-set mastered tree action to "sell",
			<input name="settings-autoSellMasteredKeepPrecious" class="saveConf" type="checkbox"<?=$settings['autoSellMasteredKeepPrecious']?" checked":""?>> except precious
			<input type="button" value="Clear all MOVE actions" onclick="actionconf('faction=general&actn=clearallsec')"><br>
			Move all trees to section: 
				<select name="actn" size="1" onchange="fAction('faction=malltosec&sec=',this.value)" >
					<option value="0">&nbsp;</option>
<?=$secHTML?>
				</select><br>
					Move other trees to section:
				<select name="actn" size="1" onchange="fAction('faction=mothtosec&sec=',this.value)" >
					<option value="0">&nbsp;</option>
<?=$secHTML?>
				</select>
				<br>
				Precious tree with min. Coins: <input class="saveConf" size="4" name="settings-preciousCoins" type="text" value="<?=$vSettings['preciousCoins']?>"><br>
				Precious tree with min. Cocos: <input class="saveConf" size="4" name="settings-preciousCocos" type="text" value="<?=$vSettings['preciousCocos']?>"><br>
				Precious tree with min. Jade:  <input class="saveConf" size="4" name="settings-preciousJade" type="text" value="<?=$vSettings['preciousJade']?>">
		</td>
	</tr>

<?php
$vUnlockedWorldtypes=load_botarray(F('unlockedworldtypes.txt'));
$vUnlockedLicences=load_botarray(F('unlockedworldlicenses.txt'));
$vSettingsWorldtype=@file_get_contents(F('worldtype.txt'));
$vworlds=array();
foreach ($vUnlockedLicences as $vUn)
	if ($vUn !== $vSettingsWorldtype) $vworlds[]=$vUn;
if (in_array($vSettingsWorldtype, $vUnlockedLicences) && count($vworlds)>0) {
?>	

	<tr>
		<th>Transport</th>
		<td>
			<input type="button" value="Clear all TRANSPORT Actions" onclick="actionconf('faction=general&actn=clearalltransp')"><br>
			Move All Trees to Farm:
				<select name="actn" size="1" onchange="fAction('faction=talltofarm&farm=',this.value)" >
					<option value="0">&nbsp;</option>
<?php
foreach ($vworlds as $vworld) {
	echo '<option value="'.$vworld.'">'.$vworld.'</option>';
}
?>
				</select>, but keep <input name="treecount" size="2" value="0" type="text" onchange="fAction('faction=trkeeptrees&keep=',this.value)">
		</tr>
<?php
}
?>

</table>
